package cn.edu.cjw.APMFP.Product.Servicve;

import java.util.ArrayList;
import java.util.HashMap;

import cn.edu.cjw.APMFP.BOMTable.pojo.BOMTable;
import cn.edu.cjw.APMFP.Product.DAO.ProductDAO;
import cn.edu.cjw.APMFP.Product.DAO.ProductDAOImpl;
import cn.edu.cjw.APMFP.Product.pojo.Product;

public class ProductServiceImpl implements ProductService {

	ProductDAO pDao = new ProductDAOImpl();

	public boolean addProduct(BOMTable bomTable, HashMap<String, Long> material, HashMap<Integer, String> workstep)
			throws Exception {

		Product product = new Product(material, workstep);
		product.setProduct(bomTable);

		if (pDao.searchProductById(product.getBId()).judge()) {
			return false;
		} else {
			return pDao.addAndUpdateProduct(product);
		}

	}

	public boolean updateProductMaterial(Product product, HashMap<String, Long> material) throws Exception {
		product.setMaterial(material);

		return pDao.addAndUpdateProduct(product);
	}

	public boolean updateProductWorkstep(Product product, HashMap<Integer, String> workstep) throws Exception {
		product.setWorkstep(workstep);
		return pDao.addAndUpdateProduct(product);
	}

	public boolean removeProduct(Product product) throws Exception {
		return pDao.removeProduct(product);
	}

	public Product searchProductById(String id) throws Exception {
		return pDao.searchProductById(id);
	}

	public ArrayList<Product> searchProductByName(String name) throws Exception {
		return pDao.searchProductByname(name);
	}

	@Override
	public ArrayList<Product> showAll() throws Exception {
		return pDao.showAll();
	}
}
